--[[
树的根节点
--]]
BTBehaviorTree = BTTask:New()

local this = BTBehaviorTree
this.taskType = BTTaskType.Root

function this:New()
	local o = {}
	setmetatable(o, self)
	self.__index = self
	return o
end

--设置起始节点
function this:SetStartTask(task)
	task.root = self
	task.parent = self
	task.layer = self.layer + 1
	self.startTask = task
end

--更新子节点层级
function this:UpdateLayer()
	self:UpdateChildLayer(self.startTask)
end

function this:UpdateChildLayer(task)
	local taskType = task.taskType
	task.layer = task.root.layer + task.layer - 1
	if (taskType == BTTaskType.Root) then
		self:UpdateChildLayer(task.startTask)
	elseif (taskType == BTTaskType.Composite or taskType == BTTaskType.Decorator) then
		for i=1,#task.childTasks do
			self:UpdateChildLayer(task.childTasks[i])
		end
	else
	end
end

function this:OnUpdate()
	if (self.startTask) then
		self.executionStatus = self.startTask:OnUpdate()
		return self.executionStatus
	end
end